<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <!-- 了解 -->
      <h2>组件添加v-model</h2>
      <p>msg: {{ msg }}</p>
      <!-- <child :value="msg" @input="getMsg"></child> -->
      <child :value="msg" @input="getMsg"></child>
    </div>

    <script src="./lib/Vue3.js"></script>
    <script>
      const { createApp } = Vue;

      const Child = {
        props: {
          value: String,
        },
        emits: ["input"],
        template: `
          <div>
            <div>child子组件</div>
            <input type="text" :value="value" @input="handleChange" />
          </div>
        `,
        methods: {
          handleChange(e) {
            this.$emit("input", e.target.value);
          },
        },
      };

      createApp({
        data() {
          return {
            msg: "123",
          };
        },
        methods: {
          getMsg(msg) {
            this.msg = msg;
          },
        },
        components: {
          Child,
        },
      }).mount("#app");
    </script>
  </body>
</html>
